/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.iscte.iul.dcti.pa.gspas.util;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import pt.iscte.iul.dcti.pa.gspas.gui.annotation.ArgsNameAnnotation;

/**
 *
 * @author Gedsimon Pereira - 58554
 * @contact gspas@iscte.pt
 *
 */
public class PropertyAccess {

    private Method method;
    private BeanType type;

    public PropertyAccess(Method method, BeanType type) {
        this.method = method;
        this.type = type;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public BeanType getType() {
        return type;
    }

    public void setType(BeanType type) {
        this.type = type;
    }

    public List<Property> getArgumentsProperties() {
        List<Property> properties = new ArrayList<>();
        Class<?>[] params = method.getParameterTypes();
        String[] argsName = argsName();
        int count = 0;
        for (Class<?> classParam : params) {
            properties.add(new Property(argsName[count], argsName[count], new ArrayList<PropertyAccess>(), PropertyType.getPropertyFromClass(classParam), classParam));
            count++;
        }
        return properties;
    }


    private String[] argsName() {
        String[] argsName = new String[method.getParameterTypes().length];
        ArgsNameAnnotation argAnnot = method.getAnnotation(ArgsNameAnnotation.class);
        if (argAnnot != null) {
            argsName = argAnnot.argsName();
        }
        return argsName;
    }

}
